package com.mingtu.guards.adapter;

import android.content.Context;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.common.base.BaseApplication;
import com.mingtu.common.utils.ConvertLatlng;
import com.mingtu.guards.R;
import com.mingtu.guards.bean.InfraredDequiBean;
import com.mingtu.guards.utils.MyConstant;

public class InfrareDequiAdapter extends BaseQuickAdapter<InfraredDequiBean.DataBean.ListBean, BaseViewHolder> {

    private Context context;

    public InfrareDequiAdapter(Context context) {
        super(R.layout.item_infrare_dequipment);
        this.context = context;
    }


    @Override
    protected void convert(@NonNull BaseViewHolder helper, InfraredDequiBean.DataBean.ListBean listBean) {
        String cameraName = listBean.getCameraName();
        String cameraCode = listBean.getCameraCode();
        int status = listBean.getStatus(); //状态 2：离线  1：在线
        String latitude = listBean.getLatitude();
        String longitude = listBean.getLongitude();
        int picCount = listBean.getPicCount();
        String address = listBean.getAddress();
        int batteryLevel = listBean.getBatteryLevel();
        String imgUrl = listBean.getImgUrl();

        if (!StringUtils.isEmpty(cameraName)) {
            helper.setText(R.id.tv_name, "设备编号：" + cameraName);
        }

        if (status == 2) {
            helper.setGone(R.id.tv_offline, true);
            helper.setGone(R.id.tv_online, false);

        } else if (status == 1) {
            helper.setGone(R.id.tv_offline, false);
            helper.setGone(R.id.tv_online, true);
        }
        if (!StringUtils.isEmpty(latitude) && !StringUtils.isEmpty(longitude)) {
            double lng = Double.parseDouble(longitude);
            double lat = Double.parseDouble(latitude);
            String myLng = ConvertLatlng.getInstance().convertToSexagesimal(lng);
            String myLat = ConvertLatlng.getInstance().convertToSexagesimal(lat);
            helper.setText(R.id.tv_lat_lng, "经纬度：" + myLng + "," + myLat);
        }

        helper.setText(R.id.tv_num, "拍摄数量：" + picCount);
        if (!StringUtils.isEmpty(address)) {
            helper.setText(R.id.tv_address, "拍摄位置：" + address);
        }

        helper.setText(R.id.tv_electric_quantity, batteryLevel * 10 + "%");

        if (batteryLevel <= MyConstant.BATTERY_WARNIG_LEVEEL) {
            helper.setTextColor(R.id.tv_electric_quantity, context.getResources().getColor(R.color.bg_color_f03));
        } else if (batteryLevel <= MyConstant.BATTERY_MIDDLE_LEVEEL) {
            helper.setTextColor(R.id.tv_electric_quantity, context.getResources().getColor(R.color.text_color_fec));
        } else {
            helper.setTextColor(R.id.tv_electric_quantity, context.getResources().getColor(R.color.colorPrimary));
        }


        Glide.with(context)
                .asDrawable()
                .load(imgUrl)
                .apply(BaseApplication.getRequestOptions())
                .into((ImageView) helper.getView(R.id.iv_picture));

        helper.addOnClickListener(R.id.layout_nav);
    }

}
